/*
 * Copyright 2010 Gal Dolber.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.jaspec;

import static junit.framework.Assert.*;

import java.util.Arrays;
import java.util.Collection;

/**
 * Jaspec collection handler.
 */
public class JaspecCollection<I> extends JaspecObject<Collection<I>> {

  public JaspecCollection(Collection<I> obj) {
    super(obj);
  }

  public JaspecCollection(Collection<I> obj, boolean not) {
    super(obj, not);
  }

  /**
   * Check that the collection have a number of...
   * 
   * @param n Number
   */
  public JaspecCollectionHave<I> have(int n) {
    return new JaspecCollectionHave<I>(this, n, Have.EXACTLY);
  }

  /**
   * Check that the collection have at most a number of...
   * 
   * @param n Number
   */
  public JaspecCollectionHave<I> have_at_most(int n) {
    return new JaspecCollectionHave<I>(this, n, Have.AT_MOST);
  }

  /**
   * Check that the collection have at least a number of...
   * 
   * @param n Number
   */
  public JaspecCollectionHave<I> have_at_least(int n) {
    return new JaspecCollectionHave<I>(this, n, Have.AT_LEAST);
  }

  /**
   * Check that the collection include certain items.
   * 
   * @param items The items
   */
  public void include(I... items) {
    boolean containsAll = obj.containsAll(Arrays.asList(items));
    if (!not) {
      assertTrue("The collection " + obj + " should include the items " + items, containsAll);
    } else {
      assertFalse("The collection: " + obj + " should not include the items: " + items, containsAll);
    }
  }

  /**
   * Check that the collection is not empty.
   */
  public void be_empty() {
    boolean empty = obj.isEmpty();
    if (!not) {
      assertTrue("The collection should be empty", empty);
    } else {
      assertFalse("The collection should not be empty", empty);
    }
  }
}
